;;; yisp-basis.el --- the basic elements of yisp

;; Copyright (C) 2007  Free Software Foundation, Inc.

;; Author: Duzy Chan <duzy@duzy.info>
;; Keywords: 

;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.

;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING.  If not, write to
;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.

;;; Commentary:

;; 

;;; Code:

(defun yisp-error (msg)
  "Invocates `error' after add prefix '[yisp][ERROR]: ' to the MSG."
  (error (format "[yisp][ERROR]: %s" msg)))

(defun yisp-warn (msg)
  "Invocates `warn' after add prefix '[yisp][WARN]: ' to the MSG."
  (let ((str (format "[yisp][WARN]: %s" msg)))
    (if (fboundp 'warn)
	(warn str)
      (message str))))

(defun yisp-message (msg)
  "Invocates `message' after adding prefix '[yisp]: ' to the MSG."
  (message (format "[yisp]: %s" msg)))

;; Safe loading requirement function
(defun yisp-require (package)
  "Make requirement on 'package', report error if requires failed."
  (let ((return-message nil))
    (if (condition-case err 
            (require package)
          (file-error
           (yisp-warn (set 'return-message (error-message-string err)))
           nil))
        (yisp-message
         (set 'return-message (format "Package %s is loaded." package))))
    return-message))

(defun yisp-load (package)
  "Load the specified 'package', report error if action failed."
  (let ((return-message nil))
    (if (condition-case err
            (load package)
          (file-error
           (yisp-warn (set 'return-message (error-message-string err)))
           nil))
        (yisp-message
         (set 'return-message (format "Package %s loaded." package))))
    return-message))

(provide 'yisp-basis)
;;; yisp-basis.el ends here
